package com.zzptc.sky.baidudemo.activities;

import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.zzptc.sky.baidudemo.R;
import com.zzptc.sky.baidudemo.base.BaseActivity;
import com.zzptc.sky.baidudemo.fragments.UpdateVersionFragment;
import com.zzptc.sky.baidudemo.vo.VersionInfo;

public class AboutOrUpdateActivity extends BaseActivity {
    private RelativeLayout rl_update;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_about_update);

        rl_update = (RelativeLayout) findViewById(R.id.rl_update);
        rl_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //startActivity(new Intent(AboutOrUpdateActivity.this,CheckUpdateActivity.class));

                startActivityForResult(new Intent(AboutOrUpdateActivity.this,CheckUpdateActivity.class),0);
            }
        });
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_about_update;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        //1无网络  2 有网。慢 无法下载 3 有网， 可以下载 4 最新版本

        switch (resultCode){
            case 1:
                //Toast.makeText(this, "当前没有网络", Toast.LENGTH_SHORT).show();
                showDialog("没有网络");
                break;
            case 2:
                //Toast.makeText(this, "当前网络较差", Toast.LENGTH_SHORT).show();
                showDialog("网络环境较差");
                break;
            case 3:
                //Toast.makeText(this, "有新版本可以更新", Toast.LENGTH_SHORT).show();
                VersionInfo versionInfo = (VersionInfo) data.getSerializableExtra("update");

                //Toast.makeText(this, versionInfo.getApkurl(), Toast.LENGTH_SHORT).show();
                FragmentManager fm = getFragmentManager();

                UpdateVersionFragment uvf = UpdateVersionFragment.getUpdateVersionFragment(versionInfo);
                uvf.show(fm,"");
                break;
            case 4:
                //Toast.makeText(this, "已经是最新版本", Toast.LENGTH_SHORT).show();
                showDialog("是最新版本");
                break;

        }
    }

    public void showDialog(String string){
        FragmentManager manager = getFragmentManager();
        UpdateVersionFragment updateVersionFragment = UpdateVersionFragment.getUpdateVersionFragment(string);
        updateVersionFragment.show(manager,"");
    }
}
